#include "StdAfx.h"
#include "Station.h"


StationBus::StationBus()
: _bus(NULL)
{
}

StationBus::~StationBus()
{
}

Bus *StationBus::get()
{
	return _bus;
}

void StationBus::set(Bus *bs)
{
	_bus = bs;
}

StationBusMgr::StationBusMgr()
{
}

StationBusMgr::~StationBusMgr()
{
	destory();
}

StationBus *StationBusMgr::create()
{
	StationBus *bs = new StationBus;

	_stationBuses.push_back(bs);

	return bs;
}

void StationBusMgr::destory(StationBus *bs)
{
	_stationBuses.remove(bs);

	delete bs;
}

void StationBusMgr::destory()
{
	while (_stationBuses.size() != 0)
	{
		destory(_stationBuses.front());
	}
}

StationBus *StationBusMgr::get(size_t index)
{
	std::list<StationBus *>::iterator it = _stationBuses.begin();
	std::advance(it, index);

	if (it == _stationBuses.end())
	{
		return NULL;
	}

	return *it;
}

//StationRoute
StationRoute::StationRoute()
:_route(NULL)
{

}

StationRoute::~StationRoute()
{

}

LightMgr *StationRoute::lightMgr()
{
	//return &_lightMgr;
	return NULL;
}

Route *StationRoute::getRoute()
{
	return _route;
}

void StationRoute::setRoute(Route *re)
{
	_route = re;
}

//Station
Station::Station(void)
: _socket(INVALID_SOCKET)
{
}

Station::~Station(void)
{
}

Database::StationRow *Station::getDB()
{
	return &_db;
}

void Station::setDB(const Database::StationRow &db)
{
	_db = db;
}

SOCKET Station::getSocket() const
{
	return _socket;
}

void Station::setSocket(SOCKET s)
{
	_socket = s;
}

void Station::recv()
{
}

void Station::send()
{
}

StationBusMgr *Station::busMgr()
{
	return &_busMgr;
}

StationRouteMgr *Station::routeMgr()
{
	return NULL;
}

//StationMgr
StationMgr::StationMgr()
{
}

StationMgr::~StationMgr()
{
	destory();
}

Station *StationMgr::create()
{
	Station *sn = new Station;

	_stations.push_back(sn);

	for (std::list<IStationMgrObserver *>::iterator it = _observers.begin(); it != _observers.end(); it++)
	{
		IStationMgrObserver *rmo = *it;

		rmo->onCreate(this, sn);
	}

	return sn;
}

void StationMgr::destory(Station *sn)
{
	_stations.remove(sn);

	delete sn;

	for (std::list<IStationMgrObserver *>::iterator it = _observers.begin(); it != _observers.end(); it++)
	{
		IStationMgrObserver *rmo = *it;

		rmo->onDestory(this, sn);
	}
}

void StationMgr::destory()
{
	while (_stations.size() != 0)
	{
		destory(_stations.front());
	}
}

Station *StationMgr::get(size_t index)
{
	std::list<Station *>::iterator it = _stations.begin();
	std::advance(it, index);

	if (it == _stations.end())
	{
		return NULL;
	}

	return *it;
}

void StationMgr::addObserver(IStationMgrObserver *rmo)
{
	_observers.push_back(rmo);
}

void StationMgr::delObserver(IStationMgrObserver *rmo)
{
	_observers.remove(rmo);
}